﻿#include "CmdDataImport.h"
#include <QFile>
#include <QDebug>
#include "BaseModule/IBaseSignal.h"
#include "PostCommandPy.h"
#include "MainWindowSignalHandler.h"
#include "DataImportConfigurationData.h"

namespace PostCommand
{
    CmdDataImport::CmdDataImport()
        : CommandBase()
    {
        this->initCmdName();
    }
    CmdDataImport::~CmdDataImport()
    {
    }

    bool CmdDataImport::execute()
    {
        bool _success = false;
        if (!m_filePath.isEmpty())
        {
            if (!m_isTextOrCsv)
            {
                emit _success = IBaseSignalInstance->singal_toolButtonDataImport(m_filePath);
            }
            else
            {
                _success = DataImportConfigurationDataInstance->TextAndCsvCustomDataConversionFromQStringAndExecute(m_customData);
            }
        }
        else
        {
            qDebug() << "CmdDataImport::execute() failed, m_filePath is empty";
        }
        return _success;
    }

    void CmdDataImport::undo()
    {
    }

    void CmdDataImport::redo()
    {
    }

    void CmdDataImport::setFilePath(QString filePath)
    {
        m_filePath = filePath;
    }
    void CmdDataImport::setIsTextOrCsv(bool isTextOrCsv)
    {
        m_isTextOrCsv = isTextOrCsv;
    }
    void CmdDataImport::setCustomData(QString customData)
    {
        m_customData = customData;
    }

}
